<?php

uploadPhoto();
	
function uploadPhoto()
{
	$fileType=$_FILES['txtPhoto']['type'];
	//echo $fileType."<br>";
	$typeArray=array("image/gif","image/jpeg","image/pjpeg");
	if(array_search($fileType,$typeArray)==null || $_FILES['txtPhoto']['error']>0)
	{
		//echo array_search($fileType,$typeArray)."<br>";
		//echo $_FILES['txtPhoto']['error']."<br>";
		echo "Invalid File";
	}
	else
	{
		//$fileName=$_FILES['txtPhoto']['name'];
		$destName=date('Y_m_d-H_m_s');
		$g_imgPath="upload_photo";
		$destPath=$g_imgPath."/".$destName;
		$res=move_uploaded_file($_FILES['txtPhoto']['tmp_name'],$destPath);
		echo $res;
		if($res==1)
		{
			echo "上传图片成功<br>";
			
			InsertPhotoData($destName,$fileType);
		}
	}
}

function InsertPhotoData($fileName,$fileType)
{
	 $host="localhost";
     $user="root";
     $pwd;
     $db="phpwind1";

	//echo $host;
	//echo $albumName;
	
	$albumId=$_POST['txtAlbumId'];
	echo $albumId."<br>";
	echo "fileName=$fileName<br>";
	
    $conn=mysql_connect($host,$user,$pwd) or die("Cannot connect sql");

    mysql_select_db($db) or die("Cannot select the db");
    $sql="insert into photo(albumId,name,title,description,type) values($albumId,'$fileName','','','$fileType')";
	
	//echo $sql;
   $res= mysql_query($sql) or die("insert Photo Error!".mysql_error());
  // $num=mysql_num_rows($res);
   
   echo $res;
}
?>